
<div style="POSITION: relative" id="content">
  <h3>easyUI 创建异步Tree</h3>
  <div id="article_content" class="article_content">
    <p>创建异步的tree,每一个tree几点<span style="font-size:18px; color:#ff0000"><strong>必须</strong></span>要有一个<span style="font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; font-size:14px; text-align:left">'id'属性 ,这个将提交回服务器去检索子节点数据.</span></p>
    <p><span style="font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; font-size:14px; text-align:left"><img src="documentation/images/1344825532_7395.png" alt=""><br>
      </span></p>
    <p>&nbsp;</p>
<h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 创建 Tree</h4>
    <pre name="code" class="html">&lt;ul id=&quot;tt&quot; class=&quot;easyui-tree&quot;  
        url=&quot;tree2_getdata.php&quot;&gt;  
&lt;/ul&gt;  </pre>
    <p></p>
    <p><span style="font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; font-size:14px; text-align:left"></span></p>
    <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 服务器端代码</h4>
    <pre name="code" class="php">$id = isset($_POST['id']) ? intval($_POST['id']) : 0;  
  
include 'conn.php';  
  
$result = array();  
$rs = mysql_query(&quot;select * from nodes where parentId=$id&quot;);  
while($row = mysql_fetch_array($rs)){  
    $node = array();  
    $node['id'] = $row['id'];  
    $node['text'] = $row['name'];  
    $node['state'] = has_child($row['id']) ? 'closed' : 'open';  
    array_push($result,$node);  
}  
  
echo json_encode($result);  
  
function has_child($id){  
    $rs = mysql_query(&quot;select count(*) from nodes where parentId=$id&quot;);  
    $row = mysql_fetch_array($rs);  
    return $row[0] &gt; 0 ? true : false;  
}  </pre>
    <h4 style="font-size:16px; color:rgb(204,0,0); margin:10px 0px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left"> 下载 EasyUI 示例:</h4>
    <div style="font-size:14px; font-family:Arial,Helvetica,'Nimbus Sans L',sans-serif; text-align:left; padding-left:50px"> <a href="http://www.jeasyui.com/tutorial/tree/download/easyui-tree2-demo.zip" target="_blank" class="download-link" style="color:rgb(0,0,255)">easyui-tree-demo.zip</a></div>
    <br>
  </div>
</div>
<SCRIPT type=text/javascript>
	dp.SyntaxHighlighter.ClipboardSwf = 'documentation/js/clipboard.swf'/*tpa=http://jeasyui.com/SyntaxHighlighter/Scripts/clipboard.swf*/;
	dp.SyntaxHighlighter.HighlightAll('code');
</SCRIPT>